import java.util.Arrays;
//2
class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode head = new ListNode();
        ListNode nh = head;
        int tmp = 0;
        while(l1 != null || l2 != null || tmp != 0){
            if(l1 != null) tmp += l1.val;
            if(l2 != null) tmp += l2.val;
            ListNode node = new ListNode(tmp%10);
            nh.next = node;
            nh = nh.next;
            tmp/=10;
            if(l1 != null) l1 = l1.next;
            if(l2 != null) l2 = l2.next;
        }
        return head.next;
    }
}
class Solution {
    public int matrixSum(int[][] nums) {
        for(int i=0; i < nums.length; i++){
            Arrays.sort(nums[i]);
        }
        int ans = 0;
        for(int j = 0; j < nums[0].length; j++){
            int max = 0;
            for(int i=0; i<nums.length; i++){
                if(max < nums[i][j]){
                    max = nums[i][j];
                }
            }
            ans += max;
        }
        return ans;
    }
}
class Solution {
    public int matrixSum(int[][] nums) {
        for(int i=0; i < nums.length; i++){
            nums[i] = abc(nums[i]);
        }
        int ans = 0;
        for(int j = 0; j < nums[0].length; j++){
            int max = 0;
            for(int i=0; i<nums.length; i++){
                if(max < nums[i][j]){
                    max = nums[i][j];
                }
            }
            ans += max;
        }
        return ans;
    }
    public int[] abc(int[] num){
        for(int i = 0; i < num.length - 1; i++){
            for(int j = 0; j < num.length -1 -i; j++){
                if(num[j] < num[j+1]){
                    int tmp = num[j];
                    num[j] = num[j+1];
                    num[j+1] = tmp;
                }
            }
        }
        return num;
    }
}
public class Tesst {
    public static void main(String[] args) {
        int[] num = {4,5,1,3,65,9,4,2};
        Solution s = new Solution();
        s.abc(num);
        System.out.println(Arrays.toString(num));
    }
}
